export function clone(obj) {
  return JSON.parse(JSON.stringify(obj))
}

export function formatDateStr(dateTime) {
  const year = dateTime.getFullYear()
  const month = dateTime.getMonth() + 1
  const day = dateTime.getDate()
  const hours = dateTime.getHours()
  const min = dateTime.getMinutes()
  const seconds = dateTime.getSeconds()

  return `${year}-${month}-${day} ${hours}:${min}:${seconds}`
}
export function parseDateStr(dateStr) {
  const dateTime = new Date(dateStr)
  const year = dateTime.getFullYear()
  const month = dateTime.getMonth() + 1
  const day = dateTime.getDate()
  const hours = dateTime.getHours()
  const min = dateTime.getMinutes()
  return {
    'year': year,
    'month': month,
    'day': day,
    'hours': hours,
    'min': min
  }
}

export function parseDateStrPadding(dateStr) {
  const dateTime = new Date(dateStr)
  return parseDatePadding(dateTime)
}

export function parseDatePadding(dateTime) {
  const year = dateTime.getFullYear()
  const month = dateTime.getMonth() + 1
  const day = dateTime.getDate()
  const hours = dateTime.getHours()
  const min = dateTime.getMinutes()
  return {
    'year': year,
    'month': paddingStr(month, 2),
    'day': paddingStr(day, 2),
    'hours': paddingStr(hours, 2),
    'min': paddingStr(min, 2)
  }
}

export function paddingStr(num, length) {
  if ((num + '').length >= length) {
    return num
  }
  return paddingStr('0' + num, length)
}

export function isDateStr(data) {
  if (isNaN(data) && !isNaN(Date.parse(data))) {
    return true
  }
  return false
}
